# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np
import pandas as pd
import os

# import IPython
# from IPython.display import Audio
# from IPython.display import Image
# import matplotlib.pyplot as plt

def dataload(DATA_PATH):
    data = pd.DataFrame(columns=['Emotion', 'Emotion intensity', 'Gender','Path'])
    for dirname, _, filenames in os.walk(DATA_PATH):
        for filename in filenames:
            file_path = os.path.join(dirname, filename)
            identifiers = filename.split('.')[0].split('-')
            emotion = (int(identifiers[2]))
            if emotion == 8: # promeni surprise sa 8 na 0
                emotion = 0
            if int(identifiers[3]) == 1:
                emotion_intensity = 'normal' 
            else:
                emotion_intensity = 'strong'
            if int(identifiers[6])%2 == 0:
                gender = 'female'
            else:
                gender = 'male'
            
            data = data.append({"Emotion": emotion,
                                "Emotion intensity": emotion_intensity,
                                "Gender": gender,
                                "Path": file_path
                                },
                                ignore_index = True
                            )
    # You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
    # You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session

    print("number of files is {}".format(len(data)))
    return data
#data.head()

# number of examples per Emotion
# fig = plt.figure()
# ax = fig.add_subplot(111)
# ax.bar(x=range(8), height=data['Emotion'].value_counts())
# ax.set_xticks(ticks=range(8))
# ax.set_xticklabels([EMOTIONS[i] for i in range(8)],fontsize=10)
# ax.set_xlabel('Emotion')
# ax.set_ylabel('Number of examples')

# # number of examples per gender
# fig = plt.figure()
# ax = fig.add_subplot(111)
# counts = data['Gender'].value_counts()
# ax.bar(x=[0,1], height=counts.values)
# ax.set_xticks(ticks=[0,1])
# ax.set_xticklabels(list(counts.index))
# ax.set_xlabel('Gender')
# ax.set_ylabel('Number of examples')

# # number of examples per emotion intensity
# fig = plt.figure()
# ax = fig.add_subplot(111)
# counts = data['Emotion intensity'].value_counts()
# ax.bar(x=[0,1], height=counts.values)
# ax.set_xticks(ticks=[0,1])
# ax.set_xticklabels(list(counts.index))
# ax.set_xlabel('Gender')
# ax.set_ylabel('Number of examples')




